<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<script>
  //建造者模式其实就是把多个工厂模式结合在一起，将一个复杂的对象相互分离，用不同的类去表示，然后再用一个总的类来包括
  //  创建一位人类
    let Human = function (param) {
    //  技能
      this.skill = param ? param.skill : '保密'
    //  兴趣爱好
      this.hobby = param ? param.hobby : '保密'
    }

//  人类原型方法
    Human.prototype = {
      getSkill : function (){
        return this.skill
      },
      getHobby : function (){
        return this.hobby
      }
    }

//  实例化姓名类
let Named = function (name) {
  let that = this;
//  构造器
//  构造函数解析姓名中的姓与名
  (function (name,that){
    that.wholeName = name;
    if(name.indexOf(' ') > -1){
      that.FirstName = name.slice(0,name.indexOf(' '));
      that.secondName = name.slice(name.indexOf(' '))
    }
  })(name,that)
}

//  实例化职位类
let Work = function (work) {
  let that = this;
//  构造器
//  构造函数中通过传入的职位特征来设置相应职位以及描述
  (function (work,that){
    switch (work){
      case 'code':
        that.work = '工程师'
        that.workDescript = '每天沉迷编程'
      case 'UI':
        that.work = '设计师'
        that.workDescript = '每天沉迷画画'
    }
  })(work,that)
}

//更换期望的职位
Work.prototype.changeWork = function (work){
      this.work = work
}

//添加
Work.prototype.changeDescript = function (setence){
  this.workDescript = setence
}
//创建一个建造者类
let Person = function (name,work){
    //创建应聘者缓存对象
    let _person = new Human()
    //创建应聘者姓名
    _person.name = new Named(name);
    //创建应聘者期望职位
    _person.work = new Work(work)
    //将创建的应聘者对象返回
    return _person
}

//创建实例
let person = new Person('yi jiamu','code')
console.log(person.getSkill())
console.log(person.getHobby())
console.log(person.name)
console.log(person.work)
console.log(person.skill)

</script>
</body>
</html>
